# coding=utf-8

from functools import wraps
from flask import request, g, abort
from flask_login import login_required
from collections import defaultdict

# roles = defaultdict(list)


def role_required(role='admin'):
    def wrapper(f):
        @wraps(f)
        def inner(*args, **kwargs):
            # 判断角色是否合规
            if g.user.role != role:
                return abort(400)

            return f(*args, **kwargs)

        return inner

    return wrapper


role_required_admin = role_required('admin')